<!doctype html>
<html>
  <head>
    <!-- MathJax -->
    <script type="text/javascript"
      src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <title>
      Caffe | Installation: Debian
    </title>

    <link rel="icon" type="image/png" href="/images/caffeine-icon.png">

    <link rel="stylesheet" href="/stylesheets/reset.css">
    <link rel="stylesheet" href="/stylesheets/styles.css">
    <link rel="stylesheet" href="/stylesheets/pygment_trac.css">

    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <!--[if lt IE 9]>
    <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
  </head>
  <body>
  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-46255508-1', 'daggerfs.com');
    ga('send', 'pageview');
  </script>
    <div class="wrapper">
      <header>
        <h1 class="header"><a href="/">Caffe</a></h1>
        <p class="header">
          Deep learning framework by <a class="header name" href="http://bair.berkeley.edu/">BAIR</a>
        </p>
        <p class="header">
          Created by
          <br>
          <a class="header name" href="http://daggerfs.com/">Yangqing Jia</a>
          <br>
          Lead Developer
          <br>
          <a class="header name" href="http://imaginarynumber.net/">Evan Shelhamer</a>
        <ul>
          <li>
            <a class="buttons github" href="https://github.com/BVLC/caffe">View On GitHub</a>
          </li>
        </ul>
      </header>
      <section>

      <h1 id="debian-installation">Debian Installation</h1>

<p>Caffe packages are available for several Debian versions, as shown in the
following chart:</p>

<div class="highlighter-rouge"><pre class="highlight"><code>Your Distro     |  CPU_ONLY  |  CUDA  | Codename
----------------+------------+--------+-------------------
Debian/oldstable|     ✘      |   ✘    | Jessie (8.0)
Debian/stable   |     ✔      |   ✔    | Stretch (9.0)
Debian/testing  |     ✔      |   ✔    | Buster
Debian/unstable |     ✔      |   ✔    | Buster
</code></pre>
</div>

<ul>
  <li>
    <p><code class="highlighter-rouge">✘ </code> You should take a look at <a href="install_apt.html">Ubuntu installation instruction</a>.</p>
  </li>
  <li>
    <p><code class="highlighter-rouge">✔ </code> You can install caffe with a single command line following this guide.</p>
  </li>
  <li>
    <p><a href="https://tracker.debian.org/pkg/caffe">Package status of CPU-only version</a></p>
  </li>
  <li>
    <p><a href="https://tracker.debian.org/pkg/caffe-contrib">Package status of CUDA version</a></p>
  </li>
</ul>

<p>Last update: 2017-07-08</p>

<h2 id="binary-installation-with-apt">Binary installation with APT</h2>

<p>Apart from the installation methods based on source, Debian users can install
pre-compiled Caffe packages from the official archive with APT.</p>

<p>Make sure that your <code class="highlighter-rouge">/etc/apt/sources.list</code> contains <code class="highlighter-rouge">contrib</code> and <code class="highlighter-rouge">non-free</code>
sections if you want to install the CUDA version, for instance:</p>

<div class="highlighter-rouge"><pre class="highlight"><code>deb http://ftp2.cn.debian.org/debian sid main contrib non-free
</code></pre>
</div>

<p>Then we update APT cache and directly install Caffe. Note, the cpu version and
the cuda version cannot coexist.</p>

<div class="highlighter-rouge"><pre class="highlight"><code>$ sudo apt update
$ sudo apt install [ caffe-cpu | caffe-cuda ]
$ caffe                                              # command line interface working
$ python3 -c 'import caffe; print(caffe.__path__)'   # python3 interface working
</code></pre>
</div>

<p>These Caffe packages should work for you out of box. However, the CUDA version
may break if your NVIDIA driver and CUDA toolkit are not installed with APT.</p>

<h4 id="customizing-caffe-packages">Customizing caffe packages</h4>

<p>Some users may need to customize the Caffe package. The way to customize
the package is beyond this guide. Here is only a brief guide of producing
the customized <code class="highlighter-rouge">.deb</code> packages.</p>

<p>Make sure that there is a <code class="highlighter-rouge">dec-src</code> source in your <code class="highlighter-rouge">/etc/apt/sources.list</code>,
for instance:</p>

<div class="highlighter-rouge"><pre class="highlight"><code>deb http://ftp2.cn.debian.org/debian sid main contrib non-free
deb-src http://ftp2.cn.debian.org/debian sid main contrib non-free
</code></pre>
</div>

<p>Then we build caffe deb files with the following commands:</p>

<div class="highlighter-rouge"><pre class="highlight"><code>$ sudo apt update
$ sudo apt install build-essential debhelper devscripts  # standard package building tools
$ sudo apt build-dep [ caffe-cpu | caffe-cuda ]          # the most elegant way to pull caffe build dependencies
$ apt source [ caffe-cpu | caffe-cuda ]                  # download the source tarball and extract
$ cd caffe-XXXX
[ ... optional, customizing caffe code/build ... ]
$ dch --local "Modified XXX"                             # bump package version and write changelog
$ debuild -B -j4                                         # build caffe with 4 parallel jobs (similar to make -j4)
[ ... building ...]
$ debc                                                   # optional, if you want to check the package contents
$ sudo debi                                              # optional, install the generated packages
$ ls ../                                                 # optional, you will see the resulting packages
</code></pre>
</div>

<p>It is a BUG if the package failed to build without any change.
The changelog will be installed at e.g. <code class="highlighter-rouge">/usr/share/doc/caffe-cpu/changelog.Debian.gz</code>.</p>

<h2 id="source-installation">Source installation</h2>

<p>Source installation under Debian/unstable and Debian/testing is similar to that of Ubuntu, but
here is a more elegant way to pull caffe build dependencies:</p>

<div class="highlighter-rouge"><pre class="highlight"><code>$ sudo apt build-dep [ caffe-cpu | caffe-cuda ]
</code></pre>
</div>

<p>Note, this requires a <code class="highlighter-rouge">deb-src</code> entry in your <code class="highlighter-rouge">/etc/apt/sources.list</code>.</p>

<h4 id="compiler-combinations">Compiler Combinations</h4>

<p>Some users may find their favorate compiler doesn’t work with CUDA.</p>

<div class="highlighter-rouge"><pre class="highlight"><code>CXX compiler |  CUDA 7.5  |  CUDA 8.0  |  CUDA 9.0  |
-------------+------------+------------+------------+
GCC-8        |     ?      |     ?      |     ?      |
GCC-7        |     ?      |     ?      |     ?      |
GCC-6        |     ✘      |     ✘      |     ✔      |
GCC-5        |     ✔ [1]  |     ✔      |     ✔      |
-------------+------------+------------+------------+
CLANG-4.0    |     ?      |     ?      |     ?      |
CLANG-3.9    |     ✘      |     ✘      |     ✔      |
CLANG-3.8    |     ?      |     ✔      |     ✔      |
</code></pre>
</div>

<p><code class="highlighter-rouge">[1]</code> CUDA 7.5 ‘s <code class="highlighter-rouge">host_config.h</code> must be patched before working with GCC-5.</p>

<p><code class="highlighter-rouge">[2]</code> CUDA 9.0: https://devblogs.nvidia.com/parallelforall/cuda-9-features-revealed/</p>

<p>BTW, please forget the GCC-4.X series, since its <code class="highlighter-rouge">libstdc++</code> ABI is not compatible with GCC-5’s.
You may encounter failure linking GCC-4.X object files against GCC-5 libraries.
(See https://wiki.debian.org/GCC5 )</p>

<h2 id="notes">Notes</h2>

<ul>
  <li>
    <p>Consider re-compiling OpenBLAS locally with optimization flags for sake of
performance. This is highly recommended for any kind of production use, including
academic research.</p>
  </li>
  <li>
    <p>If you are installing <code class="highlighter-rouge">caffe-cuda</code>, APT will automatically pull some of the
CUDA packages and the nvidia driver packages. Please be careful if you have
manually installed or hacked nvidia driver or CUDA toolkit or any other
related stuff, because in this case APT may fail.</p>
  </li>
  <li>
    <p>Additionally, a manpage (<code class="highlighter-rouge">man caffe</code>) and a bash complementation script
(<code class="highlighter-rouge">caffe &lt;TAB&gt;&lt;TAB&gt;</code>, <code class="highlighter-rouge">caffe train &lt;TAB&gt;&lt;TAB&gt;</code>) are provided.
Both of the two files are still not merged into caffe master.</p>
  </li>
  <li>
    <p>The python interface is Python 3 version: <code class="highlighter-rouge">python3-caffe-{cpu,cuda}</code>.
No plan to support python2.</p>
  </li>
  <li>
    <p>If you encountered any problem related to the packaging system (e.g. failed to install <code class="highlighter-rouge">caffe-*</code>),
please report bug to Debian via Debian’s bug tracking system. See https://www.debian.org/Bugs/ .
Patches and suggestions are also welcome.</p>
  </li>
</ul>

<h2 id="faq">FAQ</h2>

<ul>
  <li>where is caffe-cudnn?</li>
</ul>

<p>CUDNN library seems not redistributable currently. If you really want the
caffe-cudnn deb packages, the workaround is to install cudnn by yourself,
and hack the packaging scripts, then build your customized package.</p>

<ul>
  <li>I installed the CPU version. How can I switch to the CUDA version?</li>
</ul>

<p><code class="highlighter-rouge">sudo apt install caffe-cuda</code>, apt’s dependency resolver is smart enough to deal with this.</p>

<ul>
  <li>Where are the examples, the models and other documentation stuff?</li>
</ul>

<div class="highlighter-rouge"><pre class="highlight"><code>$ sudo apt install caffe-doc
$ dpkg -L caffe-doc
</code></pre>
</div>


      </section>
  </div>
  </body>
</html>
